﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using ARR.UI.ViewModels;
using Telerik.Windows.Controls.GridView;
using ARR.Entities;

namespace ARR.UI.Views
{
    /// <summary>
    /// Interaction logic for BenchmarkEdit.xaml
    /// </summary>
    public partial class BenchmarkEditView : Window
    {
        public BenchmarkEditView()
        {
            InitializeComponent();

            StoresGV.RowLoaded += new EventHandler<Telerik.Windows.Controls.GridView.RowLoadedEventArgs>(StoresGV_RowLoaded);
        }

        void StoresGV_RowLoaded(object sender, Telerik.Windows.Controls.GridView.RowLoadedEventArgs e)
        {
            BenchmarkEditViewModel vm = this.DataContext as BenchmarkEditViewModel;

            if (vm != null && vm.CurrentBenchmark.StoreGroup != null && vm.CurrentBenchmark.StoreGroup.Members != null && vm.CurrentBenchmark.StoreGroup.Members.Any())
            {
                if (e.Row is GridViewRow && !(e.Row is GridViewNewRow))
                {
                    Store store = e.DataElement as Store;

                    if (vm.CurrentBenchmark.StoreGroup.Members.Select(st => st.Store.Id).Contains(store.Id))
                        e.Row.IsSelected = true;
                }
            }
        }        
    }
}
